package com.zy.ivideo.service;

import com.zy.ivideo.entity.BulletScreenEntity;
import com.zy.ivideo.entity.CommentEntity;
import com.zy.ivideo.entity.ResponseEntity;
import com.zy.ivideo.repository.BulletScreenRepository;
import com.zy.ivideo.utils.ResponseUtils;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

@Service
public class BulletScreenService {
    @Autowired
    BulletScreenRepository repository;

    /**
     * 发布弹幕信息
     * @param entity
     * @return
     */
    public ResponseEntity<BulletScreenEntity> publishBulletScreen(@RequestBody
                                                                  @ApiParam(value = "弹幕实体", name = "entity", required = true)
                                                                          BulletScreenEntity entity){
        BulletScreenEntity result = repository.save(entity);
        if (result!=null){
            return ResponseUtils.success(result);
        }
        return ResponseUtils.failed("发布弹幕失败");
    }

    /**
     * 删除弹幕信息
     * @param id
     * @return
     */
    public ResponseEntity<Boolean> removeBulletScreen(Long id){
        try{
            repository.deleteById(id);

        }catch (Exception exception){
            return ResponseUtils.failed("删除弹幕发生错误，info:"+exception.getMessage());
        }
        return ResponseUtils.success(true);
    }

    /**
     * 获取弹幕信息
     * @param datatype 数据类型 0-simplevideo 1-multitypevideo
     * @param itemid 资源id
     * @return
     */
    public ResponseEntity<List<BulletScreenEntity>> getBulletScreenInfo(int datatype,String itemid){
        List<BulletScreenEntity> result = repository.getBulletScreenInfo(datatype, itemid);
        if (result!=null&&result.size()>0){
            return ResponseUtils.success(result);
        }
        return ResponseUtils.failed("没有获取到弹幕信息");
    }
}
